/***************************************************************
 *
 * (c) 2008 Markus Dittrich 
 *
 * This program is free software; you can redistribute it 
 * and/or modify it under the terms of the GNU General Public 
 * License Version 3 as published by the Free Software Foundation. 
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License Version 3 for more details.
 *
 * You should have received a copy of the GNU General Public 
 * License along with this program; if not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place - Suite 330, 
 * Boston, MA 02111-1307, USA.
 *
 ****************************************************************/

#ifndef DATASELECTORWIDGET_H
#define DATASELECTORWIDGET_H

/* boost include */
#include <boost/utility.hpp>

/* STL includes */
#include <vector>
//#include <iostream>

/* Qt includes */
#include <QList>
#include <QListWidget>

/* local includes */
#include "basic_definitions.h"

/* forward declarations */
class QMouseEvent;
class QListWidgetItem;



/*****************************************************************
 *
 * class DataNameList provides a slightly beefed up QListWidget
 * to keep track of data names
 *
 ****************************************************************/
class DataNameWidget 
  : 
    public QListWidget,
    public boost::noncopyable
{

  Q_OBJECT


public:

  explicit DataNameWidget(QWidget* parent = 0);
  bool Init();


signals:

  void right_mouse_click(QMouseEvent* anEvent);
  void right_mouse_double_click(QMouseEvent* anEvent);


protected:

  void mousePressEvent(QMouseEvent* anEvent);
  void mouseDoubleClickEvent(QMouseEvent* anEvent);


private:

  /* indicates successful construction */
  int status_;

  /* pointer to parent */
  QWidget* parent_;
};



/****************************************************************
 *
 * DataSelectorWidget provides a widget for selecting, hiding
 * and deleting currently loaded datasets
 *
 ***************************************************************/
class DataSelectorWidget 
  : 
    public QWidget,
    public boost::noncopyable
{
  Q_OBJECT


public:

  explicit DataSelectorWidget(QWidget* parent = 0);
  bool Init();
  
  void add_data_item(const QString& name, const QColor& labelColor);
  QList<QString> get_selected_item_names() const;
  int num_selected_items() const;
  

public slots:

  void show_data_selector_actions_(QMouseEvent* anEvent);
  void toggle_visibility_(QMouseEvent* anEvent);
  void change_label_color(const QString& labelName, 
      const QColor& colorName);


signals:

  void hide_items(bool status, QList<QString> dataList);
  void delete_items(QList<QString> dataList);
  void selected_data_item_changed(int row);
  void create_histogram();


private:

  /* indicates successful construction */
  int status_;

  /* pointer to parent */
  QWidget* parent_;

  /* interface generation function */
  void generate_data_list_();

  /* member functions */
  void hide_data_(bool status);
  void delete_data_();
  QString generate_widget_string_(const QString& rawName, 
      bool isHidden) const;

  /* member widgets */
  DataNameWidget* dataNameList_;

  /* define static constants to label available
   * QVariants data names in DataNameList */
  const static int FULL_NAME = Qt::UserRole;
  const static int HIDDEN_FLAG = Qt::UserRole + 1;
};


#endif
